package com.etoak.controller;


import com.etoak.common.core.vo.PageVo;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.service.DishesService;
import com.etoak.vo.DishesVo;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author etoak
 * @since 2025-08-25
 */
@RestController
@RequestMapping("/dishes")
public class DishesController {

    @Autowired
    DishesService dishesService;

    //添加接口
    @PostMapping
    public ResultVO<Object> add(@Valid @RequestBody Dishes dishes) throws Exception {
        dishesService.add(dishes);
        return ResultVO.success();
    }
    //查询接口
    @GetMapping("/list")
    public ResultVO<Object> list(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "10") int pageSize,
            Dishes dishes
    ){
        PageVo<DishesVo> pageVo = dishesService.getList(pageNum, pageSize, dishes);
        return ResultVO.success(pageVo);
    }

    /*
    * 更新接口
    * */
    @PutMapping("/{id}")
    public ResultVO<Object> update(@PathVariable int id,@RequestBody Dishes dishes) throws Exception {
        dishesService.updateDishes(id,dishes);
        return ResultVO.success();
    }

    /*删除接口*/
    @DeleteMapping("/{id}")
    public ResultVO<Object> delete(@PathVariable int id){
        dishesService.delete(id);
        return ResultVO.success();
    }
}

